package com.work.common.util;


import com.work.common.exp.WorkException;
import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;

import java.util.Collection;
import java.util.Objects;

public class AssertUtil {
    public static void isTrue(boolean expression, String message, int code) {
        if (!expression) {
            throw new WorkException(code, message);
        }
    }

    public static void isTrue(boolean expression, String message) {
        if (!expression) {
            throw new WorkException(message);
        }
    }

    public static void isFalse(boolean expression, String message, int code) {
        isTrue(!expression, message, code);
    }

    public static void isFalse(boolean expression, String message){
        isTrue(!expression, message);
    }

    public static void isNull(Object object, String message) {
        isTrue(Objects.isNull(object), message);
    }
    public static void nonNull(Object object, String message) {
        isTrue(Objects.nonNull(object), message);
    }

    public static void isEmpty(String str, String message) {
        isTrue(StringUtils.isEmpty(str), message);
    }
    public static void nonEmpty(String str, String message) {
        isTrue(StringUtils.isNotEmpty(str), message);
    }
    public static void isBlank(String str, String message) {
        isTrue(StringUtils.isBlank(str), message);
    }
    public static void nonBlank(String str, String message) {
        isTrue(StringUtils.isNotBlank(str), message);
    }
    public static void isCollectionEmpty(Collection<?> collection, String message) {
        isTrue(CollectionUtils.isEmpty(collection), message);
    }
    public static void nonCollectionEmpty(Collection<?> collection, String message) {
        isTrue(CollectionUtils.isNotEmpty(collection), message);
    }
}
